package com.lanou.sfu.songforu.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.lanou.sfu.songforu.R;
import com.lanou.sfu.songforu.entity.SongMenuEntity;
import com.lanou.sfu.songforu.utils.image.ImageUtils;

import java.util.List;

import it.sephiroth.android.library.picasso.Picasso;

/**
 * Created by dllo on 15/10/30.
 */
public class SongMenuGridViewAdapter extends BaseAdapter {
    private Context mContext;
    private List<SongMenuEntity.ContentEntity> datas;

    public SongMenuGridViewAdapter(Context context, List<SongMenuEntity.ContentEntity> lists) {
        datas = lists;
        mContext = context;
    }

    public void addDatas(List<SongMenuEntity.ContentEntity> lists){
        datas = lists;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return datas.size();
    }

    @Override
    public SongMenuEntity.ContentEntity getItem(int position) {
        return datas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null){
            holder = new ViewHolder();
            convertView = LayoutInflater.from(mContext).inflate(R.layout.songsmenu_gridview_item, null);
            holder.content = (TextView) convertView.findViewById(R.id.songsmenu_album_hostbotoomText);
            holder.num = (TextView) convertView.findViewById(R.id.songsmenu_album_num);
            holder.image = (ImageUtils) convertView.findViewById(R.id.songsmenu_album_pic);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
            SongMenuEntity.ContentEntity contentEntity = getItem(position);

        if (contentEntity != null){
            holder.num.setText(contentEntity.getListenum());
            holder.content.setText(contentEntity.getTitle());
            Picasso.with(mContext).load(contentEntity.getPic_w300()).into(holder.image);
        }
        return convertView;
    }
    public class ViewHolder{
        private ImageUtils image;
        private TextView content, num;
    }

}
